layui.use(['layer', 'form', 'table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 系统管理--角色管理
     */
    var WxUser = {
        tableId: "wxUserTable",    //表格id
        condition: {
        	nickname: ""
        }
    };

    /**
     * 初始化表格的列
     */
    WxUser.initColumn = function () {
        return [[
        	{type: 'checkbox'},
            {field: 'userId', hide: true, sort: true, title: '用户id'},
        	{field: 'headimgurl',width: 130,align:'center', templet:'#imgTpl', title: '头像'},
        	{field: 'openid', sort: true, title: '微信ID'},
            {field: 'nickname', sort: true, title: '昵称'},
            {field: 'sex', sort: true, title: '性别'},
            {field: 'phone', sort: true, title: '电话'},
            {field: 'subscribe', sort: true, title: '是否关注'},
            {field: 'subscribetime', sort: true, title: '关注时间'},
            {field: 'countrys', sort: true, title: '地址'},
        ]];
    };

    /**
     * 点击查询按钮
     */
    WxUser.search = function () {
        var queryData = {};
        queryData['nickname'] = $("#nickname").val();
        table.reload(WxUser.tableId, {where: queryData, page:{curr: 1}});
    };


    /**
     * 导出excel按钮
     */
    WxUser.exportExcel = function () {
        var checkRows = table.checkStatus(WxUser.tableId);
        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + WxUser.tableId,
        url: Feng.ctxPath + '/wx_user/list',
        page: true,
        height: "full-158",
        cellMinWidth: 100,
        cols: WxUser.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        WxUser.search();
    });
    // 导出excel
    $('#btnExp').click(function () {
    	WxUser.exportExcel();
    });
    // 工具条点击事件
    table.on('tool(' + WxUser.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
    });
});
